/*
 * Copyright (c) 2019 - 2020 IoT Company of Midea Group.
 *
 * File Name 	    : 
 * Description	    : rtos adaptor
 *
 * Version	        : v0.1
 * Author			: 
 * Date	            : 2019/09/15  refactoring
 * History	        : 
 */
#ifndef __MS_OSAL_QUEUE_H__
#define __MS_OSAL_QUEUE_H__

#include <stdint.h>
#include <ms_osal.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief	Create a new queue instance
 * @param[in]	qhandle: 		A handle to the newly created queue
 * @param[in]	name: 		A descriptive name for the queue
 * @param[in]	msgsize: 		The number of bytes each item in the queue will require
 * @param[in]	queue_length: The maximum number of items that the queue can contain
 * @return if successly, return MS_OSAL_RESULT_SUCCESS, \n
 *         otherwise return MS_OSAL_RESULT_ERROR
 **/
ms_osal_result_t ms_osal_queue_create(ms_osal_queue_t *qhandle,
										  const char *name, 
										  int32_t msgsize,
										  int32_t queue_length);

/**
 * @brief	Post an item to the back of a queue
 * @param[in]	qhandle: The handle to the queue on which the item is to be posted
 * @param[in]	msg: A pointer to the item that is to be placed on the queue
 * @param[in]	msecs: The maximum amount of time the task should block waiting for space to become available on the queue
 * @return if successly, return MS_OSAL_RESULT_SUCCESS, \n
 *         otherwise return MS_OSAL_RESULT_ERROR
 **/
ms_osal_result_t ms_osal_queue_send(ms_osal_queue_t *qhandle,
										void *msg,										
										uint32_t msecs);

/**
 * @brief	Receive an item from a queue
 * @param[in]	qhandle : The handle to the queue from which the item is to be received
 * @param[out]	msg : Pointer to the buffer into which the received item will be copied
 * @param[in]	msecs : The maximum amount of time the task should block waiting for an item to receive
 * @return if successly, return MS_OSAL_RESULT_SUCCESS, \n
 *         otherwise return MS_OSAL_RESULT_ERROR
 **/
ms_osal_result_t ms_osal_queue_recv(ms_osal_queue_t *qhandle,
										void *msg, 
										uint32_t msecs);

/**
 * @brief	Delete a queue - freeing all the memory allocated for storing of items placed on the queue
 * @param[in]	qhandle : handle to the queue to be deleted
 * @return if successly, return MS_OSAL_RESULT_SUCCESS, \n
 *         otherwise return MS_OSAL_RESULT_ERROR
 **/
ms_osal_result_t ms_osal_queue_delete(ms_osal_queue_t *qhandle);

/**
 * @brief	Get the number of messages stored in a queue
 * @param[in]	qhandle: A handle to the queue being queried
 * @return	The number of messages available in the queue
 **/
int32_t ms_osal_queue_get_msgs_waiting(ms_osal_queue_t *qhandle);

#ifdef __cplusplus
}
#endif

#endif // __MS_OSAL_QUEUE_H__

